package com.qing.apple.filter.demo02;

import com.qing.apple.filter.bean.Apple;
import com.qing.apple.filter.bean.InitApple;
import com.qing.apple.filter.demo02.comparator.AppleComparator;
import com.qing.apple.filter.demo02.service.AppleService;

import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;

public class Demo3 {

	public static void main(String[] args) {
		InitApple.getApples().sort(new AppleComparator());

		InitApple.getApples().sort(new Comparator<Apple>() {
			@Override
			public int compare(Apple o1, Apple o2) {
				return o1.getWeight().compareTo(o2.getWeight());
			}
		});

		InitApple.getApples().sort((Apple a1,Apple a2)->a1.getWeight().compareTo(a2.getWeight()));

		InitApple.getApples().sort((a1,a2)->a1.getWeight().compareTo(a2.getWeight()));

		InitApple.getApples().sort(Comparator.comparing(apple -> apple.getWeight()));


		//苹果排序
		InitApple.getApples().sort(Comparator.comparing(Apple::getWeight));
		//逆序
		InitApple.getApples().sort(Comparator.comparing(Apple::getWeight).reversed());
		//重量相同如何排序
		InitApple.getApples().sort(Comparator.comparing(Apple::getWeight).reversed().thenComparing(Apple::getColor));


		Predicate<Apple> redApple = (Apple apple)->apple.getColor().equals("red");
		Predicate<Apple> notRedApple=redApple.negate() //取非红色的苹果
				.and(apple->apple.getWeight()>150) //并且总量大于150
				.or(apple -> apple.getColor().equals("yellow"));  //或者是黄色的

		List<Apple> apples=AppleService.filter(InitApple.getApples(),notRedApple);
		System.out.println(apples);


	}
}
